// pages/SuSong/signList/signList.js
import request from '../../../utils/config.js';
import util from '../../../utils/util.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: util.timetrans(new Date(), 'day'),
    signList:[],
    pageNum:0,
    totalPage:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  // 日期选择
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
    this.getSignList(1)
  },
  goDetails: function(e) {
    console.log(e)
    app.globalData.signInfo=e.currentTarget.dataset.info
    wx.navigateTo({
      url: '../signDetails/signDetails',
    })
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  getSignList: function (pageNum){
    let _this = this;
    let send={
      signDate: this.data.date,
      pageNum: pageNum,
      pageSize:10
    }
    if(pageNum==1){
      this.setData({ signList:[]})
    }
    wx.showLoading({ title: ' ', mask: true })
    request.requestMisApi("get", "saleSignRecords/subordinates", send, (res) => {
      wx.hideLoading()
      if (res.code == '00') {
        if (pageNum == 1 && JSON.parse(res.body).length == 0) {
          wx.showToast({ title: '暂无数据', icon: 'none', duration: 1000 });
        }
        console.log("succ", JSON.parse(res.body))
        let tempArr = JSON.parse(res.body)
        let signList = _this.data.signList;
        tempArr.map((item)=>{
          item.signTimeStr = util.timetrans(item.signTime, 'timeHM');
          item.statusStr = util.filter.signStatus(item.status);
          item.signReasonStr = util.filter.signReason(item.signReasonId);
          item.weekDate = util.filter.getWeek(item.signTime) + ' '+ util.timetrans(item.signTime, 'day');
          item.useTimeStr = util.filter.getTimeLength(item.useTime / 1000);
          if (item.images){
            item.imagesArr = item.images.split('&&')
          }else{
            item.imagesArr =[]
          }
          signList.push(item)
        })
        this.setData({
          signList,
          pageNum: pageNum,
          totalPage: res.totalPage,
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'none',
          duration: 2000
        })
      }
    }, (res) => {
      console.log("获取失败", res)
    });
  },//滚动到底部
  lower: function (e) {
    let pageNum = this.data.pageNum;
    let totalPage = this.data.totalPage;
    // console.log("pageNum===", pageNum)
    console.log("totalPage====pageNum", totalPage, '=====', pageNum)
    if (pageNum < totalPage) {
      this.getSignList(pageNum*1+1)
    } else {
      //显示没有更多字样
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getSignList(1)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})